layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 周转容器管理明细管理
     */
    var TurnoverContainerDetailed = {
        tableId: "turnoverContainerDetailedTable"

    };

    /**
     * 初始化表格的列
     */
    TurnoverContainerDetailed.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'packNumber', sort: true, title: '容器编号'},
            {field: 'operationType', sort: true, title: '操作类型'},
            {field: 'operator', sort: true, title: '操作人'},
            {field: 'sendTime', sort: true, title: '操作时间'},
            {field: 'warehouseName', sort: true, title: '仓库'},
            {field: 'customerName', sort: true, title: '门店'},
            {field: 'driverName', sort: true, title: '司机姓名'},
            {field: 'carNumber', sort: true, title: '车牌号'},
            {field: 'tel', sort: true, title: '司机手机号'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    TurnoverContainerDetailed.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(TurnoverContainerDetailed.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
                 // 搜索按钮点击事件
                 $('#btnSearch').click(function () {
                     TurnoverContainerDetailed.search();
                 });
                 // 添加按钮点击事件
                 $('#btnAdd').click(function () {
                     TurnoverContainerDetailed.openAddDlg();
                 });
                 // 导出excel
                 $('#btnExp').click(function () {
                     TurnoverContainerDetailed.exportExcel();
                 });
            }
        });
    };

    /**
     * 弹出添加对话框
     */
    TurnoverContainerDetailed.openAddDlg = function () {
        window.location.href = Feng.ctxPath + '/turnoverContainerDetailed/add';
    };

    // /**
    //  * 导出excel按钮
    //  */
    // TurnoverContainerDetailed.exportExcel = function () {
    //     var checkRows = table.checkStatus(TurnoverContainerDetailed.tableId);
    //     if (checkRows.data.length === 0) {
    //         Feng.error("请选择要导出的数据");
    //     } else {
    //         table.exportFile(tableResult.config.id, checkRows.data, 'xls');
    //     }
    // };


    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    TurnoverContainerDetailed.openEditDlg = function (data) {
        window.location.href = Feng.ctxPath + '/turnoverContainerDetailed/edit?id=' + data.id;
    };

    // /**
    //  * 点击删除
    //  *
    //  * @param data 点击按钮时候的行数据
    //  */
    // TurnoverContainerDetailed.onDeleteItem = function (data) {
    //     var operation = function () {
    //         var ajax = new $ax(Feng.ctxPath + "/turnoverContainerDetailed/delete", function (data) {
    //             Feng.success("删除成功!");
    //             table.reload(TurnoverContainerDetailed.tableId);
    //         }, function (data) {
    //             Feng.error("删除失败!" + data.responseJSON.message + "!");
    //         });
    //         ajax.set("id", data.id);
    //         ajax.start();
    //     };
    //     Feng.confirm("是否删除?", operation);
    // };

    var data = JSON.parse(localStorage.getItem('packNumber'));
    var condition = data.key;
    console.log(condition);
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + TurnoverContainerDetailed.tableId,
        url: Feng.ctxPath + '/turnoverContainerDetailed/list?condition=' + condition ,
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: TurnoverContainerDetailed.initColumn()
    });

    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/turnoverContainer'
    });

});
